package com.github.dapeng.soa;
        import com.github.dapeng.soa.info.serializer.*;

        import com.github.dapeng.core.*;
        import com.github.dapeng.org.apache.thrift.*;
        import com.github.dapeng.org.apache.thrift.protocol.*;

        import com.github.dapeng.core.definition.SoaServiceDefinition;
        import com.github.dapeng.core.definition.SoaFunctionDefinition;

        import java.io.BufferedReader;
        import java.io.InputStreamReader;

        import java.util.Optional;
        import java.util.concurrent.CompletableFuture;
        import java.util.concurrent.Future;

        /**
        * Autogenerated by Dapeng-Code-Generator (1.2.2)
        *
        * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
        *  @generated
        **/
        public class CalculateServiceCodec {

        
            public static class calcualteWordCount_args {
            
                private String filename;
                public String getFilename(){
                return this.filename;
              }
                public void setFilename(String filename){
                this.filename = filename;
              }
              
                private String word;
                public String getWord(){
                return this.word;
              }
                public void setWord(String word){
                this.word = word;
              }
              

            @Override
            public String toString(){
              StringBuilder stringBuilder = new StringBuilder("{");
                
      stringBuilder.append("\"").append("filename").append("\":\"").append(filename).append("\",");
    
      stringBuilder.append("\"").append("word").append("\":\"").append(word).append("\",");
    
                if(stringBuilder.lastIndexOf(",") > 0)
                stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(","));
                stringBuilder.append("}");

              return stringBuilder.toString();
            }

          }

            public static class calcualteWordCount_result {

            
                  private Integer success;
                  public Integer getSuccess(){
                  return success;
                }

                  public void setSuccess(Integer success){
                  this.success = success;
                }


                  @Override
                  public String toString(){
                  StringBuilder stringBuilder = new StringBuilder("{");
                    
      stringBuilder.append("\"").append("success").append("\":").append(success).append(",");
    
                    stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(","));
                    stringBuilder.append("}");

                  return stringBuilder.toString();
                }

                
          }

            public static class CalcualteWordCount_argsSerializer implements BeanSerializer<calcualteWordCount_args>{
            
      @Override
      public calcualteWordCount_args read(TProtocol iprot) throws TException{

      calcualteWordCount_args bean = new calcualteWordCount_args();
      TField schemeField;
      iprot.readStructBegin();

      while(true){
        schemeField = iprot.readFieldBegin();
        if(schemeField.type == TType.STOP){ break;}

        switch(schemeField.id){
          
              case 1:
              if(schemeField.type == TType.STRING){
              String elem0 = iprot.readString();
       bean.setFilename(elem0);
            }else{
              TProtocolUtil.skip(iprot, schemeField.type);
            }
              break;
            
              case 2:
              if(schemeField.type == TType.STRING){
              String elem0 = iprot.readString();
       bean.setWord(elem0);
            }else{
              TProtocolUtil.skip(iprot, schemeField.type);
            }
              break;
            
          
            default:
            TProtocolUtil.skip(iprot, schemeField.type);
          
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();

      validate(bean);
      return bean;
    }
    
      @Override
      public void write(calcualteWordCount_args bean, TProtocol oprot) throws TException{

      validate(bean);
      oprot.writeStructBegin(new TStruct("calcualteWordCount_args"));

      
            oprot.writeFieldBegin(new TField("filename", TType.STRING, (short) 1));
            String elem0 = bean.getFilename();
            oprot.writeString(elem0);
            
            oprot.writeFieldEnd();
          
            oprot.writeFieldBegin(new TField("word", TType.STRING, (short) 2));
            String elem1 = bean.getWord();
            oprot.writeString(elem1);
            
            oprot.writeFieldEnd();
          
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }
    
      public void validate(calcualteWordCount_args bean) throws TException{
      
              if(bean.getFilename() == null)
              throw new SoaException(SoaBaseCode.NotNull, "filename字段不允许为空");
            
              if(bean.getWord() == null)
              throw new SoaException(SoaBaseCode.NotNull, "word字段不允许为空");
            
    }
    

            @Override
            public String toString(calcualteWordCount_args bean) { return bean == null ? "null" : bean.toString(); }

          }

            public static class CalcualteWordCount_resultSerializer implements BeanSerializer<calcualteWordCount_result>{
            @Override
            public calcualteWordCount_result read(TProtocol iprot) throws TException{

              calcualteWordCount_result bean = new calcualteWordCount_result();
              TField schemeField;
              iprot.readStructBegin();

              while(true){
                schemeField = iprot.readFieldBegin();
                if(schemeField.type == TType.STOP){ break;}

                switch(schemeField.id){
                  case 0:  //SUCCESS
                  if(schemeField.type == TType.I32){
                     int elem0 = iprot.readI32();
       bean.setSuccess(elem0);
                  }else{
                    TProtocolUtil.skip(iprot, schemeField.type);
                  }
                  break;
                  /*
                  case 1: //ERROR
                  bean.setSoaException(new SoaException());
                  new SoaExceptionSerializer().read(bean.getSoaException(),iprot);
                  break A;
                  */
                  default:
                  TProtocolUtil.skip(iprot, schemeField.type);
                }
                iprot.readFieldEnd();
              }
              iprot.readStructEnd();

              validate(bean);
              return bean;
            }
            
      @Override
      public void write(calcualteWordCount_result bean, TProtocol oprot) throws TException{

      validate(bean);
      oprot.writeStructBegin(new TStruct("calcualteWordCount_result"));

      
            oprot.writeFieldBegin(new TField("success", TType.I32, (short) 0));
            Integer elem0 = bean.getSuccess();
            oprot.writeI32(elem0);
            
            oprot.writeFieldEnd();
          
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }
    
            
      public void validate(calcualteWordCount_result bean) throws TException{
      
    }
    

            @Override
            public String toString(calcualteWordCount_result bean) { return bean == null ? "null" : bean.toString(); }
          }

            public static class calcualteWordCount<I extends com.github.dapeng.soa.service.CalculateService> extends SoaFunctionDefinition.Sync<I, calcualteWordCount_args, calcualteWordCount_result>
            {
              public calcualteWordCount()
              {
                super("calcualteWordCount", new CalcualteWordCount_argsSerializer(),  new CalcualteWordCount_resultSerializer());
              }

              @Override
              public calcualteWordCount_result apply(I iface, calcualteWordCount_args calcualteWordCount_args)
              {

                calcualteWordCount_result result = new calcualteWordCount_result();


                try {
                result.success = iface.calcualteWordCount(calcualteWordCount_args.filename,calcualteWordCount_args.word);
                } catch (SoaException e) {
                e.printStackTrace();
              }
                

                return result;

              }

            }
          
            public static class calcualteWordsCount_args {
            
                private String fileName;
                public String getFileName(){
                return this.fileName;
              }
                public void setFileName(String fileName){
                this.fileName = fileName;
              }
              

            @Override
            public String toString(){
              StringBuilder stringBuilder = new StringBuilder("{");
                
      stringBuilder.append("\"").append("fileName").append("\":\"").append(fileName).append("\",");
    
                if(stringBuilder.lastIndexOf(",") > 0)
                stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(","));
                stringBuilder.append("}");

              return stringBuilder.toString();
            }

          }

            public static class calcualteWordsCount_result {

            
                  private java.util.Map<String, Integer> success;
                  public java.util.Map<String, Integer> getSuccess(){
                  return success;
                }

                  public void setSuccess(java.util.Map<String, Integer> success){
                  this.success = success;
                }


                  @Override
                  public String toString(){
                  StringBuilder stringBuilder = new StringBuilder("{");
                    
      stringBuilder.append("\"").append("success").append("\":").append(success).append(",");
    
                    stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(","));
                    stringBuilder.append("}");

                  return stringBuilder.toString();
                }

                
          }

            public static class CalcualteWordsCount_argsSerializer implements BeanSerializer<calcualteWordsCount_args>{
            
      @Override
      public calcualteWordsCount_args read(TProtocol iprot) throws TException{

      calcualteWordsCount_args bean = new calcualteWordsCount_args();
      TField schemeField;
      iprot.readStructBegin();

      while(true){
        schemeField = iprot.readFieldBegin();
        if(schemeField.type == TType.STOP){ break;}

        switch(schemeField.id){
          
              case 1:
              if(schemeField.type == TType.STRING){
              String elem0 = iprot.readString();
       bean.setFileName(elem0);
            }else{
              TProtocolUtil.skip(iprot, schemeField.type);
            }
              break;
            
          
            default:
            TProtocolUtil.skip(iprot, schemeField.type);
          
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();

      validate(bean);
      return bean;
    }
    
      @Override
      public void write(calcualteWordsCount_args bean, TProtocol oprot) throws TException{

      validate(bean);
      oprot.writeStructBegin(new TStruct("calcualteWordsCount_args"));

      
            oprot.writeFieldBegin(new TField("fileName", TType.STRING, (short) 1));
            String elem0 = bean.getFileName();
            oprot.writeString(elem0);
            
            oprot.writeFieldEnd();
          
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }
    
      public void validate(calcualteWordsCount_args bean) throws TException{
      
              if(bean.getFileName() == null)
              throw new SoaException(SoaBaseCode.NotNull, "fileName字段不允许为空");
            
    }
    

            @Override
            public String toString(calcualteWordsCount_args bean) { return bean == null ? "null" : bean.toString(); }

          }

            public static class CalcualteWordsCount_resultSerializer implements BeanSerializer<calcualteWordsCount_result>{
            @Override
            public calcualteWordsCount_result read(TProtocol iprot) throws TException{

              calcualteWordsCount_result bean = new calcualteWordsCount_result();
              TField schemeField;
              iprot.readStructBegin();

              while(true){
                schemeField = iprot.readFieldBegin();
                if(schemeField.type == TType.STOP){ break;}

                switch(schemeField.id){
                  case 0:  //SUCCESS
                  if(schemeField.type == TType.MAP){
                    TMap _map0 = iprot.readMapBegin();
        java.util.Map<String,Integer> elem0 = new java.util.HashMap<>(_map0.size);
        for(int _i0 = 0; _i0 < _map0.size; ++ _i0){
          String elem1 = iprot.readString();
           int elem2 = iprot.readI32();
          elem0.put(elem1, elem2);
        }
        iprot.readMapEnd();
       bean.setSuccess(elem0);
                  }else{
                    TProtocolUtil.skip(iprot, schemeField.type);
                  }
                  break;
                  /*
                  case 1: //ERROR
                  bean.setSoaException(new SoaException());
                  new SoaExceptionSerializer().read(bean.getSoaException(),iprot);
                  break A;
                  */
                  default:
                  TProtocolUtil.skip(iprot, schemeField.type);
                }
                iprot.readFieldEnd();
              }
              iprot.readStructEnd();

              validate(bean);
              return bean;
            }
            
      @Override
      public void write(calcualteWordsCount_result bean, TProtocol oprot) throws TException{

      validate(bean);
      oprot.writeStructBegin(new TStruct("calcualteWordsCount_result"));

      
            oprot.writeFieldBegin(new TField("success", TType.MAP, (short) 0));
            java.util.Map<String, Integer> elem0 = bean.getSuccess();
            
          oprot.writeMapBegin(new TMap(TType.STRING, TType.I32, elem0.size()));
          for(java.util.Map.Entry<String, Integer> _it0 : elem0.entrySet()){

          String elem1 = _it0.getKey();
          Integer elem2 = _it0.getValue();
          oprot.writeString(elem1);
          oprot.writeI32(elem2);
        }
          oprot.writeMapEnd();
        
            
            oprot.writeFieldEnd();
          
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }
    
            
      public void validate(calcualteWordsCount_result bean) throws TException{
      
              if(bean.getSuccess() == null)
              throw new SoaException(SoaBaseCode.NotNull, "success字段不允许为空");
            
    }
    

            @Override
            public String toString(calcualteWordsCount_result bean) { return bean == null ? "null" : bean.toString(); }
          }

            public static class calcualteWordsCount<I extends com.github.dapeng.soa.service.CalculateService> extends SoaFunctionDefinition.Sync<I, calcualteWordsCount_args, calcualteWordsCount_result>
            {
              public calcualteWordsCount()
              {
                super("calcualteWordsCount", new CalcualteWordsCount_argsSerializer(),  new CalcualteWordsCount_resultSerializer());
              }

              @Override
              public calcualteWordsCount_result apply(I iface, calcualteWordsCount_args calcualteWordsCount_args)
              {

                calcualteWordsCount_result result = new calcualteWordsCount_result();


                try {
                result.success = iface.calcualteWordsCount(calcualteWordsCount_args.fileName);
                } catch (SoaException e) {
                e.printStackTrace();
              }
                

                return result;

              }

            }
          

        public static class getServiceMetadata_args {

          @Override
          public String toString() {
            return "{}";
          }
        }


        public static class getServiceMetadata_result {

          private String success;

          public String getSuccess() {
            return success;
          }

          public void setSuccess(String success) {
            this.success = success;
          }

          @Override
          public String toString() {
            StringBuilder stringBuilder = new StringBuilder("{");
              stringBuilder.append("\"").append("success").append("\":\"").append(this.success).append("\",");
              stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(","));
              stringBuilder.append("}");

            return stringBuilder.toString();
          }
        }

        public static class GetServiceMetadata_argsSerializer implements BeanSerializer<getServiceMetadata_args> {

          @Override
          public getServiceMetadata_args read(TProtocol iprot) throws TException {

            getServiceMetadata_args bean =new getServiceMetadata_args();
            TField schemeField;
            iprot.readStructBegin();

            while (true) {
              schemeField = iprot.readFieldBegin();
              if (schemeField.type == TType.STOP) {
                break;
              }
              switch (schemeField.id) {
                default:
                TProtocolUtil.skip(iprot, schemeField.type);

              }
              iprot.readFieldEnd();
            }
            iprot.readStructEnd();

            validate(bean);
            return bean;
          }


          @Override
          public void write(getServiceMetadata_args bean, TProtocol oprot) throws TException {

            validate(bean);
            oprot.writeStructBegin(new TStruct("getServiceMetadata_args"));
            oprot.writeFieldStop();
            oprot.writeStructEnd();
          }

          public void validate(getServiceMetadata_args bean) throws TException {}

          @Override
          public String toString(getServiceMetadata_args bean) {
            return bean == null ? "null" : bean.toString();
          }

        }

        public static class GetServiceMetadata_resultSerializer implements BeanSerializer<getServiceMetadata_result> {
          @Override
          public getServiceMetadata_result read(TProtocol iprot) throws TException {

            getServiceMetadata_result bean = new getServiceMetadata_result();
            TField schemeField;
            iprot.readStructBegin();

            while (true) {
              schemeField = iprot.readFieldBegin();
              if (schemeField.type == TType.STOP) {
                break;
              }

              switch (schemeField.id) {
                case 0:  //SUCCESS
                if (schemeField.type == TType.STRING) {
                  bean.setSuccess(iprot.readString());
                } else {
                  TProtocolUtil.skip(iprot, schemeField.type);
                }
                break;
                default:
                TProtocolUtil.skip(iprot, schemeField.type);
              }
              iprot.readFieldEnd();
            }
            iprot.readStructEnd();

            validate(bean);
            return bean;
          }

          @Override
          public void write(getServiceMetadata_result bean, TProtocol oprot) throws TException {

            validate(bean);
            oprot.writeStructBegin(new TStruct("getServiceMetadata_result"));

            oprot.writeFieldBegin(new TField("success", TType.STRING, (short) 0));
            oprot.writeString(bean.getSuccess());
            oprot.writeFieldEnd();

            oprot.writeFieldStop();
            oprot.writeStructEnd();
          }

          public void validate(getServiceMetadata_result bean) throws TException {

            if (bean.getSuccess() == null)
            throw new SoaException(SoaBaseCode.NotNull, "success字段不允许为空");
          }

          @Override
          public String toString(getServiceMetadata_result bean) {
            return bean == null ? "null" : bean.toString();
          }
        }

        public static class getServiceMetadata<I extends com.github.dapeng.soa.service.CalculateService> extends SoaFunctionDefinition.Sync<I, getServiceMetadata_args, getServiceMetadata_result> {
          public getServiceMetadata() {
            super("getServiceMetadata", new GetServiceMetadata_argsSerializer(), new GetServiceMetadata_resultSerializer());
          }

          @Override
          public getServiceMetadata_result apply(I iface, getServiceMetadata_args args) {
            getServiceMetadata_result result = new getServiceMetadata_result();

            try (InputStreamReader isr = new InputStreamReader(CalculateServiceCodec.class.getClassLoader().getResourceAsStream("com.github.dapeng.soa.service.CalculateService.xml"));
            BufferedReader in = new BufferedReader(isr)) {
              int len = 0;
              StringBuilder str = new StringBuilder("");
              String line;
              while ((line = in.readLine()) != null) {

                if (len != 0) {
                  str.append("\r\n").append(line);
                } else {
                  str.append(line);
                }
                len++;
              }
              result.success = str.toString();

            } catch (Exception e) {
              e.printStackTrace();
              result.success = "";
            }

            return result;
          }

        }

        @SuppressWarnings("unchecked")
        public static class Processor<I extends com.github.dapeng.soa.service.CalculateService> extends SoaServiceDefinition<com.github.dapeng.soa.service.CalculateService>
        {

          public Processor(com.github.dapeng.soa.service.CalculateService iface, Class<com.github.dapeng.soa.service.CalculateService> ifaceClass)
          {
            super(iface, ifaceClass, buildMap(new java.util.HashMap<>()));
          }

          @SuppressWarnings("unchecked")
          private static <I extends com.github.dapeng.soa.service.CalculateService> java.util.Map<String, SoaFunctionDefinition<I, ?, ?>> buildMap(java.util.Map<String, SoaFunctionDefinition<I, ?, ?>> processMap)
          {
            
                processMap.put("calcualteWordCount", new calcualteWordCount());
              
                processMap.put("calcualteWordsCount", new calcualteWordsCount());
              
            processMap.put("getServiceMetadata", new getServiceMetadata());
            return processMap;
          }
        }

      }
      